<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>采购订单入库单产品对比</title>
    <script type="text/javascript">
      Ext.onReady(function(){
        
        var vendor =  Ext.create('Ext.form.ComboBox', {
          labelWidth:40,
          fieldLabel: '供应商',
          store: vendorStore,
          valueField: 'id',
          displayField: 'name',
          name: 'vendor_id',          
          loadingText: '搜索中...',
          anchor: '95%',                    
          minChars: 0,
          editable:false          
        });

        var purchaseOrderNumber = Ext.create('Ext.form.field.Text', {
          labelWidth:55,
          fieldLabel: '采购单号',
          name: 'purchase_order_number',
          anchor: '95%'
        });

        var auditingStatus = Ext.create('Ext.form.ComboBox', {
          labelWidth:55,
          fieldLabel: '审批状态',
          store: auditStatusStore,
          displayField:'text',
          typeAhead: true,
          anchor: '95%',
          mode: 'local',
          name: 'auditing_status',
          forceSelection: true,
          editable:false,
          valueField: 'value',
          emptyText:''
        })

        var beginDate = Ext.create('Ext.form.field.Date', {
          labelWidth:55,
          fieldLabel: '到货日期',
          name: 'begin_date',
          id: 'e_begin_date',
          format: 'Y-m-d', //格式化日期
          //disabledDays: [0,6],	//不让选择周六，周日
          //disabledDaysText: "周末要休息",
          invalidText: "您输入的日期格式不对，正确格式为2010-01-01",          
          anchor: '95%',
          vtype: 'daterange',
          endDateField: 'e_end_date'
        });

        var endDate = Ext.create('Ext.form.field.Date', {
          labelWidth:55,
          fieldLabel: '至',
          name: 'end_date',
          id: 'e_end_date',
          format: 'Y-m-d', //格式化日期
          //disabledDays: [0,6],	//不让选择周六，周日
          //disabledDaysText: "周末要休息",
          invalidText: "您输入的日期格式不对，正确格式为2010-01-01",          
          anchor: '95%',
          vtype: 'daterange',
          startDateField: 'e_begin_date'
        });

        var showEntryInfo = Ext.create('Ext.form.field.Checkbox', {
          name: 'entry_info',
          clearCls: 'allow-float',
          itemCls: 'float-left',
          fieldLabel: '显示入库明细'
        })

        //产品
        var productCBB = Ext.create('Ext.form.ComboBox', {
          store: productStore,
          labelWidth:40,
          fieldLabel: '产品',
          emptyText: '请选择...',
          valueField: 'id',
          displayField: 'name',
          name: 'product_id',
          loadingText: '搜索中...',
          anchor: '100%',
          pageSize: 10,
          minChars: 0,
          listConfig: {
            loadingText: 'Searching...',
            getInnerTpl: function() {
              return '<div style="float:left; width:200px" data-qtip="{name}">{name:ellipsis(18)}</div><div style="float:left; width:110px">{number}</div>{is_suit}';
            }
          }
        });
        
        
        var submitButton = Ext.create('Ext.Button', {
          text: '搜索',
          iconCls: 'finding',
          handler: function(){
            if (queryFormPanel.form.isValid()) {
              productBalanceDS.removeAll();
              productBalanceDS.getProxy().extraParams.purchase_order_number = purchaseOrderNumber.getValue();
              productBalanceDS.getProxy().extraParams.auditing_status = auditingStatus.getValue();

              productBalanceDS.getProxy().extraParams.begin_date = beginDate.getRawValue();
              productBalanceDS.getProxy().extraParams.end_date = endDate.getRawValue();
              productBalanceDS.getProxy().extraParams.vendor_id = vendor.getValue();
              productBalanceDS.getProxy().extraParams.entry_info = showEntryInfo.getValue();
              productBalanceDS.getProxy().extraParams.product_id = productCBB.getValue();
              productBalanceDS.getProxy().extraParams.start = 0;
              productBalanceDS.load();
            }
          }
        });

        var clearButton = Ext.create('Ext.Button', {
          text: '清空',
          width:50,
          handler: function(){
            queryFormPanel.form.reset();
          }
        });

        var queryFormPanel = Ext.create('Ext.form.Panel', {
          fieldDefaults: {
            labelWidth: 85,
            labelAlign: 'right'
          },
          width: screenWidth-165,
          frame : true,
          border:false,
          items: [{
              xtype: 'fieldset',
              defaults: {width: 1100},
              title: '查询条件',
              border: true,
              items: [{
                  layout: 'column',
                  xtype: 'container',
                  items: [{
                      columnWidth: .2,
                      layout: 'anchor',
                      xtype: 'container',
                      items: [purchaseOrderNumber]
                    }, {
                      columnWidth: .2,
                      layout: 'anchor',
                      xtype: 'container',
                      items: [auditingStatus]
                    }, {
                      columnWidth: .3,
                      layout: 'anchor',
                      xtype: 'container',
                      items: [vendor]
                    },{
                      columnWidth: .1,
                      layout: 'anchor',
                      xtype: 'container',
                      items: [showEntryInfo]
                    }, {
                      columnWidth: .15,
                      layout: 'anchor',
                      xtype: 'container',
                      items: [submitButton]
                    }]
                },{
                  layout: 'column',
                  xtype: 'container',
                  items: [{
                      columnWidth: .2,
                      layout: 'anchor',
                      xtype: 'container',
                      items: [beginDate]
                    }, {
                      columnWidth: .2,
                      layout: 'anchor',
                      xtype: 'container',
                      items: [endDate]
                    },{
                      columnWidth: .4,
                      layout: 'anchor',
                      xtype: 'container',
                      items: [productCBB]
                    }, {
                      columnWidth: .15,
                      layout: 'anchor',
                      xtype: 'container',
                      items: [clearButton]
                    }]
                }]
            }]
        });
        //显示采购订单操作时的窗口介面。
        //----------------------------------采购订单Grid-------------------------

        Ext.define('ProductNeedEntry', {
          extend : 'Ext.data.Model',
          fields : [{
              name: 'id'
            },{
              name: 'auditing_status'
            },{
              name: 'entry_order_number'
            },{
              name: 'purchase_order_number'
            },{
              name: 'product_name'
            },{
              name: 'product_number'
            },{
              name: 'purchase_quantity'
            }, {
              name: 'action_date'
            }, {
              name: 'auditing_status'
            }, {
              name: 'vendor_name'
            }, {
              name: 'department_name'
            } ,{
              name: 'entry_quantity',
              type: 'int'
            }, {
              name: 'store_status'
            }]
        });
        
        //采购订单Grid Store
        var productBalanceDS = Ext.create('Ext.data.Store', {
          //autoDestroy : true,
          model : 'ProductNeedEntry',
          proxy : {
            type : 'ajax',
            url : '/purchase_order/getProductNeedEntry',
            reader : {
              type : 'json',
              root : 'root',
              totalProperty : 'totalProperty'// 数据集记录总数
            }
          }
        });
        
        //生成要订单的产品的Grid
        var productBalanceGrid = Ext.create('Ext.grid.Panel', {
          title:'采购订单与入库单对比列表',
          store: productBalanceDS,
          columns : [Ext.create('Ext.grid.RowNumberer',{width:45}),{
              header: 'DB',
              dataIndex: 'id',
              width: 50
            },{
              header: '采购订单单号',
              dataIndex: 'purchase_order_number',
              width: 170
            },{
              header: '采购订单状态',
              dataIndex: 'auditing_status',
              renderer: auditingStatusRender,
              width: 90
            },{
              header: '供应商',
              dataIndex: 'vendor_name',
              width: 90
            },{
              header: '部门',
              dataIndex: 'department_name',
              width: 70
            },{
              header: '产品名称',
              dataIndex: 'product_name',
              width: 230
            },{
              header: '产品编号',
              dataIndex: 'product_number',
              width: 80
            },{
              header: '采购数量',
              dataIndex: 'purchase_quantity',
              align:'right',
              width: 75
            },{
              header: '审批状态',
              dataIndex: 'auditing_status',
              width: 60,
              renderer: auditingStatusRender
            },{
              header: '发货日期',
              dataIndex: 'action_date',
              renderer: Ext.util.Format.dateRenderer('Y-m-d'),width: 80
            },{
              header: '入库单单号',
              dataIndex: 'entry_order_number',
              width: 120
            },{
              header: '入库数量',
              dataIndex: 'entry_quantity',
              align:'right',
              width: 75
            },{
              header: '入库状态',
              dataIndex: 'store_status',
              renderer: dealWithStatusRender,
              width: 70
            }
          ],
          loadMask: true,
          width: screenWidth-165,
          height: screenHeight-360,
          frame: true,
          //title: '进货品种列表',
          //plain:true,
          //plugins: checkColumn,
          bbar: Ext.create('Ext.toolbar.Paging', {
            pageSize: pageSize,
            store: productBalanceDS,
            displayInfo: true,
            displayMsg: "显示第 {0} 条到 {1} 条记录，一共 {2} 条",
            emptyMsg: "没有记录"
          })          
        });    

        //总的panel
        var workbenchPanel = Ext.create('Ext.form.Panel', {
          width: screenWidth-165,
          height: screenHeight-245,
          frame:false,          
          layout: {type: 'table',columns:1},          
          items:[queryFormPanel,productBalanceGrid]
        });
        workbenchPanel.render("product_need_entry_workbench_panel");
      })
    </script>
  </head>
  <body>
    <div id="product_need_entry_workbench_panel"></div>
  </body>
</html>